import { create } from "zustand";
interface BearState {
  bears: number;
  isAuthorization: boolean;
  userId?: number;
  userEmail: string;
  username: string;
  headPic: string;
  phoneNumber: string | null;
  nickName: string;
  signature: string;
  hobbies: string;
  increase: (by: number) => void;
  isLogin: () => void;
  setId: (id:number)=> void;
  setEmail: (email:string) => void;
  setUserName: (name:string) =>void;
  setHeadPic: (userHeadPic:string)=> void;
  setPhoneNumber: (userPhoneNumber:string) =>void;
  setNickName: (userNickName:string)=> void;
  setSignature: (userSignature:string)=> void;
  setHobbies:(userHobbies:string)=> void;
}
const useBearStore = create<BearState>()((set) => ({
  bears: 0,
  isAuthorization: false,
  id: -1,
  userEmail: "",
  username: "",
  headPic: "",
  phoneNumber: "",
  nickName: "",
  signature: "",
  hobbies: "",
  setId:(id:number)=> set(()=>({userId:id})),
  setEmail:(email:string)=> set(()=>({userEmail:email})),
  setUserName: (name:string) => set(()=>({username:name})),
  setHeadPic: (userHeadPic:string)=>set(()=>({headPic:userHeadPic})),
  setPhoneNumber: (userPhoneNumber:string)=> set(()=>({phoneNumber:userPhoneNumber})),
  setNickName: (userNickName:string)=>set(()=>({nickName:userNickName})),
  setSignature: (userSignature:string)=>set(()=>({signature:userSignature})),
  setHobbies: (userHobbies:string)=>set(()=>({hobbies: userHobbies})),
  increase: (by) => set((state) => ({ bears: state.bears + by })),
  isLogin: () => set(() => ({ isAuthorization: true })),
  unLogin: () => set(() => ({ isAuthorization: false })),
}));

//zustand的实现原理是什么，我感觉用zustand蛮简单的。
export default useBearStore;
